The Calendar Shop
Create your own calendar with illustrations from popular cartoonists. The Calendar Shop program shows how it can be done.
Keeping track of time is a major industry. Historically, calendars have defined weeks and months quite differently from today. This program will create a calendar for any given year. It can be altered to create fantasy calendars without Mondays and historical calendars with 10-day weeks or 28-day months.
Problem Statement
The Python Code section contains an incomplete program to print a calendar for a year specified by the user. An integer function, NumberOfDaysIn, and a function, PrintMonth, are missing. Add the code for the missing sub programs. Don't change any of the existing code. Sample output - the first half of the calendar for 2020 - appears on the next page. Verify that your program produces identical output for the given months.
The function NumberOfDaysIn determines the number of days in each month of the specified year. It requires two integer arguments representing a month (1 for January, 2 for February, and so on) and a year. It should return the specified number of days in the month. For January, March, May, July, August, October, and December, it should return 31. For April, June, September, and November, it should return 30. For February, it should return 28 or 29, depending on whether the year is a leap year.
Recall that a year is a leap year (its February has 29 days) when it is divisible by 4 and not by 100, or divisible by 400.
The function PrintMonth prints each month of the year as shown in the sample output. It takes three integer arguments: the month to be printed, the year (as in NumberOfDaysIn), and the first day of the month (0 for Sunday, 1 for Monday, and so on). Exactly one blank line is to be printed between successive months.
Analysis
3.1 Which of the following years are leap years: 2010, 2020, 2014, 2017, 2000?
Analysis, Reflection
3.2 What are aspects of the problem specification that potentially will lead to bugs in the code?
Preparation
This case study introduces repeat loops, functions, and boolean variables; it also uses if and case statements, functions, and value parameters.
Output for the First Half of 2020
January 2020
S | M | T | W | T | F | S |
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
February 2020
S | M | T | W | T | F | S |
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
March 2020
S | M | T | W | T | F | S |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
April 2020
S | M | T | W | T | F | S |
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 |
May 2020
S | M | T | W | T | F | S |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
June 2020
S | M | T | W | T | F | S |
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |